package com.ziq.zcamp.manager

import android.app.Activity
import com.ziq.base.manager.MMKVManager
import com.ziq.zcamp.dialog.PrivacyDialog

//隐私管理
class PrivacyManager {

    companion object {

        const val KEY_PRIVACY_AGREE = "key_privacy_agree"
        const val KEY_PRIVACY_DIALOG_SHOWED = "key_privacy_dialog_showed"

        fun isAgreedPrivacy(): Boolean {
            return MMKVManager.mmkv.decodeBool(KEY_PRIVACY_AGREE, false)
        }

        fun storeAgreedPrivacy() {
            MMKVManager.mmkv.encode(KEY_PRIVACY_AGREE, true)
        }

        fun isPrivacyHasShowed(): Boolean {
            return MMKVManager.mmkv.decodeBool(KEY_PRIVACY_DIALOG_SHOWED, false)
        }

        fun storePrivacyDialogShowed() {
            MMKVManager.mmkv.encode(KEY_PRIVACY_DIALOG_SHOWED, true)
        }

        fun checkPrivacy(context: Activity, action: ()->Unit){
            if(isAgreedPrivacy()){
                action.invoke()
            } else {
                PrivacyDialog(context,
                    onCancel = {
                    },
                    onConfirm = {
                        storeAgreedPrivacy()
                        action.invoke()
                    }
                ).show()
            }
        }

    }

}